package org.cainiao.basic.reactive;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

/**
 * Reactor 的 JavaDoc 的图片地址参考：<br />
 * https://projectreactor.io/docs/core/release/api/reactor/core/publisher/doc-files/marbles/switchIfEmptyForMono.svg
 * <p>
 * Author: Cai Niao(wdhlzd@163.com)<br />
 */
public class ReactiveTest {

    public static void main(String[] args) {
        test();
        try {
            TimeUnit.SECONDS.sleep(10);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static void test() {
        Mono<String> noData = Mono.empty();
        Mono<String> data = Mono.just("foo");
        Flux<Integer> numbersFromFiveToSeven = Flux.range(5, 3);
    }

    public static void test1() {
        Flux<String> seq1 = Flux.just("foo", "bar", "foobar");
        Flux<String> seq2 = Flux.fromIterable(Arrays.asList("foo", "bar", "foobar"));
    }

    private static void test2() {
        Flux<Long> interval = Flux.interval(Duration.ofSeconds(1));
        interval.subscribe(System.out::println);
    }
}
